import {getCardDetail, putCardUpdate} from '@/api/card.js';
export const editMixins = {
  data() {
    return {}
  },
  onLoad() {
    this.getInit()
  },
  methods: {
	async getInit(){
		const cardTemp = getApp().globalData.cardTemp
		if(cardTemp.cardId){
			this.fromData = cardTemp
		}else{
			try{
				const res = await getCardDetail()
				getApp().globalData.cardTemp = res.data
				for(let i in this.fromData){
					this.fromData[i] = res.data[i]
				}
			}catch(e){
				console.log('获取编辑名片信息失败',e)
				//TODO handle the exception
			}
		}
	},
	putInfo(){
		uni.showLoading({
			title:'保存中...',
			icon:'none'
		})
		this.fromData.cardStyleId = this.fromData.styleId
		this.fromData.cardStyleName = this.fromData.styleName
		putCardUpdate(this.fromData).then(res=>{
			if(res.data){ uni.navigateBack() }
		}).finally(()=>{
			uni.hideLoading()
		})
	}
  }
}